#include "structure/Crane.h"
#include "Constants.h"
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform2.hpp>
#include <glm/gtx/projection.hpp>

Crane::Crane(GLuint programHandler, GLShaderConfig shaderConfig, float width, float height) :
	GLStructure(programHandler, shaderConfig),
	width(width),
	height(height) {

	tower = new Tower(programHandler, shaderConfig, width, height - CABIN_HEIGHT);
	cabin = new Cabin(programHandler, shaderConfig, CABIN_WIDTH, width, CABIN_HEIGHT);

	structures.push_back(cabin);
	structures.push_back(tower);
}

Crane::~Crane() {
	structures.clear();

	delete tower;
	delete cabin;
}

void Crane::updateComponents() {
	tower->transform(transformationMatrix);

	glm::mat4 transformation = glm::translate(transformationMatrix, glm::vec3(0, 0, height - CABIN_HEIGHT));
	cabin->transform(transformation);
}

void Crane::update (glm::mat4 viewMatrix, glm::mat4 modelMatrix) {
	updateComponents();
	std::list<GLStructure*>::iterator it = structures.begin();
	for ( ; it != structures.end(); it++ ) {
		(*it)->update(viewMatrix, modelMatrix);
	}
}
